Chapter 23 ggplot2 tutorial
ggplot(gapminder, aes(x = gdpPercap, y = lifeExp)) +
geom_point()

p <- ggplot(gapminder, aes(x = gdpPercap, y = lifeExp))
p + geom_point()

ggplot(gapminder, aes(log10(gdpPercap), y = lifeExp )) +
geom_point()

p + geom_point() +
scale_x_log10() ## better way to log transfrom, consist with ggplot2 syntax

p <- p + scale_x_log10()
p + geom_point(aes(color = continent))

plot(gapminder, aes(x = gdpPercap, y = lifeExp, color = continent)) +
geom_point() + scale_x_log10()

## NULL
p + geom_point(alpha = (1/3), size = 3)

p + geom_point() + geom_smooth()
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'

p + geom_point() + geom_smooth(lwd = 3, se = FALSE)
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'

p + geom_point() + geom_smooth(lwd = 3, se = FALSE, method = "lm")

p + aes(color = continent) + geom_point() + geom_smooth(lwd = 3, se = FALSE)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

p + geom_point(alpha = (1/3), size = 3) +
facet_wrap(~ continent)

p + geom_point(alpha = (1/3), size = 3) +
facet_wrap(~ continent) +
geom_smooth( lwd = 2, se = FALSE)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

ggplot(gapminder, aes(x = lifeExp, y = year, color = continent)) + geom_jitter(alpha = 1/3, size = 3) +
geom_smooth(se = FALSE)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

ggplot(gapminder, aes(x = year, y = lifeExp, color = continent)) + geom_jitter(alpha = 1/3, sie = 3) +
facet_wrap(~ continent, scales = "free_x") +
scale_color_manual(values = continent_colors)
## Warning: Ignoring unknown parameters: sie

ggplot(subset(gapminder, continent != "Oceania"),
aes(x = year, y = lifeExp, group = country, color = country)) +
geom_line(lwd = 1, show_guide = FALSE) + facet_wrap(~ continent) +
scale_color_manual(values = country_colors) +
theme_bw() + theme(strip.text = element_text(size = rel(1.1)))
## Warning: `show_guide` has been deprecated. Please use `show.legend`
## instead.

ggplot(gapminder, aes(x = year, y = lifeExp, color = continent)) +
geom_jitter(alpha = 1/3, size = 3) +
geom_smooth(lwd = 2,se = FALSE) +
facet_wrap(~ continent, scales= "free_x") +
scale_color_manual(values = continent_colors)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

ggplot(gapminder, aes(x = gdpPercap, y = lifeExp)) +
scale_x_log10() + geom_bin2d()

?geom_bin2d